<template>
    <div>
        <Modal
         title="修改地址"
         :value="value"
         @on-ok="save"
         @on-visible-change="visibleChange"
        >
            <Form :ref="formId" :rules="rules" :model="model" :label-width="80">
                <FormItem label="收货人" prop="personName">
                    <Input v-model="model.personName" :maxlength="32" :minlength="2"></Input>
                </FormItem>
                <FormItem label="手机" prop="phoneNumber">
                    <Input v-model="model.phoneNumber" :maxlength="32" :minlength="2"></Input>
                </FormItem>
                <FormItem label="收货地址" prop="county">
                    <address-select v-model="model"></address-select>
                </FormItem>
                <FormItem label="详细地址" prop="detailedAddress">
                    <Input v-model="model.detailedAddress" type="textarea" :maxlength="32" :minlength="2"></Input>
                </FormItem>
                <FormItem label="" prop="personName">
                    <Checkbox v-model="model.isDefault">设为默认地址</Checkbox>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button @click="cancel">取消</Button>
                <Button @click="save" type="primary">保存</Button>
            </div>
        </Modal>
    </div>
</template>
<script lang="ts">
import { Component, Vue,Inject, Prop,Watch } from 'vue-property-decorator';
import Util from '../../../lib/util'
import ModalBase from '../../../lib/ModalBase'
import AddressSelect from './address-select.vue'

@Component({
    components: { AddressSelect }
})
export default class CreateAddress extends ModalBase{
    @Prop({type:Object}) address:any;
    get model():any {
        return this.address;
    }
    rules = {
        personName:[{required: true, message:"", trigger: 'blur'}],
        phoneNumber:[{required: true, message:"", trigger: 'blur'}],
        province:[{required: true, message:"", trigger: 'change'}],
        city:[{required: true, message:"", trigger: 'change'}],
        county:[{required: true, message:"", trigger: 'change'}],
        detailedAddress:[{required: true, message:"", trigger: 'blur'}]
    }
    async saveFunc():Promise<Boolean> {
        var response = await this.put("MemberShippingAddress/Update", this.model);
        return response.success;
    }
}
</script>

